package com.ruoyi.DataManage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.DataManage.domain.Province;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.DataManage.domain.University;
import com.ruoyi.DataManage.service.IUniversityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 高校名录管理Controller
 *
 * @author CehnFneg
 * @date 2024-04-11
 */
@RestController
@RequestMapping("/DataManage/university")
public class UniversityController extends BaseController {
    @Autowired
    private IUniversityService universityService;

    /**
     * 查询高校名录管理列表
     */
    @PreAuthorize("@ss.hasPermi('DataManage:university:list')")
    @GetMapping("/list")
    public TableDataInfo list(University university) {
        startPage();
        List<University> list = universityService.selectUniversityList(university);
        return getDataTable(list);
    }

    /**
     * 导出高校名录管理列表
     */
    @PreAuthorize("@ss.hasPermi('DataManage:university:export')")
    @Log(title = "高校名录管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, University university) {
        List<University> list = universityService.selectUniversityList(university);
        ExcelUtil<University> util = new ExcelUtil<University>(University.class);
        util.exportExcel(response, list, "高校名录管理数据");
    }

    /**
     * 获取高校名录管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('DataManage:university:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        University university = universityService.selectUniversityById(id);
        return success(university);
    }

    /**
     * 新增高校名录管理
     */
    @PreAuthorize("@ss.hasPermi('DataManage:university:add')")
    @Log(title = "高校名录管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody University university) {
        return toAjax(universityService.insertUniversity(university));
    }

    /**
     * 修改高校名录管理
     */
    @PreAuthorize("@ss.hasPermi('DataManage:university:edit')")
    @Log(title = "高校名录管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody University university) {
        return toAjax(universityService.updateUniversity(university));
    }

    /**
     * 删除高校名录管理
     */
    @PreAuthorize("@ss.hasPermi('DataManage:university:remove')")
    @Log(title = "高校名录管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(universityService.deleteUniversityByIds(ids));
    }

    @GetMapping("/provincelist")
    public AjaxResult provinceList()
    {
        List<Province> provinceList = universityService.getProvinceList();
        return AjaxResult.success(provinceList);
    }
}
